package com.tian.job;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author tianwc  公众号：java后端技术全栈、面试专栏
 * @version 1.0.0
 * 在线刷题 1200+题和1000+篇干货文章：<a href="https://woaijava.cc/">博客地址</a>
 * <p>
 * 支付订单查询定时任务
 * <p>
 * 在线编辑 Core 表达式 https://www.pppet.net/
 */
@Slf4j
@Component
public class PayOrderQueryTask {

    /**
     * 每5分钟执行一次
     */
    @Scheduled(cron = "0 0/5 * * * ? ")
    public void queryPayOrder() {

    }

    /*private void doPayOrderStatus(List<ChargeBalanceRecord> chargeBalanceRecordList) {
        for (ChargeBalanceRecord chargeBalanceRecord : chargeBalanceRecordList) {
            //调微信 支付订单查询接口
            WxPayService wxService = new WxPayServiceImpl();
            WxPayOrderQueryResult wxPayOrderQueryResult;
            try {
                wxPayOrderQueryResult = wxService.queryOrder(chargeBalanceRecord.getThirdTradeNo(), chargeBalanceRecord.getOrderNo());
            } catch (WxPayException e) {
                log.error("查询订单异常", e);
                //遇到异常跳过
                continue;
            }
            String tradeState = wxPayOrderQueryResult.getTradeState();
            *//*
     *  交易状态.
     *   trade_state
     *   是
     *   String(32)
     *   SUCCESS
     *   SUCCESS—支付成功,REFUND—转入退款,NOTPAY—未支付,CLOSED—已关闭,REVOKED—已撤销（刷卡支付）,USERPAYING--用户支付中,PAYERROR--支付失败(其他原因，如银行返回失败)
     *//*
            Integer status = chargeBalanceRecord.getStatus();
            if (WxTradeStateEnum.CLOSED.getState().equals(tradeState) ||
                    WxTradeStateEnum.NOTPAY.getState().equals(tradeState) ||
                    WxTradeStateEnum.REVOKED.getState().equals(tradeState) ||
                    WxTradeStateEnum.PAYERROR.getState().equals(tradeState)) {
                status = WxPayStatusEnum.FAILED.getStatus();
            } else if (WxTradeStateEnum.USERPAYING.getState().equals(tradeState)) {
                //支付中
                continue;
            } else if (WxTradeStateEnum.SUCCESS.getState().equals(tradeState)) {
                status = WxPayStatusEnum.SUCCESS.getStatus();
            } else {
                log.error("支付状态未知：tradeState={}", tradeState);
            }
            chargeBalanceRecord.setStatus(status);
            //更新本地数据库中 支付订单状态
            chargeBalanceRecordMapper.updateByPrimaryKey(chargeBalanceRecord);
        }*/

}